"""
查询
"""
from pymysql import Connection
conn = None
try:
    conn = Connection(
        host='localhost',
        port=3306,
        user='root',
        passwd='root',
        charset='utf8',
        database='db2',
        autocommit=True
    )

    cursor = conn.cursor()
    sql = """
        select * from t_user
    """

    cursor.execute(sql)
    # 获取查询结果
    # cursor.fetchall() 获取多个结果
    # cursor.fetchone() 获取一个结果
    result = cursor.fetchall()
    # print(result,type(result))
    for item in result:
        print(item)
except Exception as e:
    print(e)
finally:
    if conn:
        conn.close()